package com.naiterui.ehp.bs.doctor.controller;

import com.naiterui.common.repository.page.PageParamVO;
import com.naiterui.common.repository.page.PageVO;
import com.naiterui.ehp.bp.bo.consult.CommentDetailBO;
import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.constants.SwaggerTags;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.support.exception.PublicService;
import com.naiterui.ehp.bp.support.exception.ResponseVO;
import com.naiterui.ehp.bs.doctor.exception.ExceptionCodes;
import com.naiterui.ehp.bs.doctor.service.IConsultCommentService;
import com.naiterui.ehp.bs.doctor.vo.patient.ConsultCommentVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * @Description 评价和投诉
 * @Author gongbaoqiang
 * @Date 2020/6/30 10:34 AM
 */
@Slf4j
@Api(tags = {SwaggerTag.DOCTOR + SwaggerTag.CONSULT_COMMENT})
@Validated
@RestController
@RequestMapping("ad/consult/comment")
public class AdConsultCommentController {

    @Autowired
    private IConsultCommentService commentService;

    @ApiOperation(value = "评价内容")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentId", value = "评价Id", required = true, dataType = "long", paramType = "query")
    })
    @PostMapping("detail")
    public ResponseVO<ConsultCommentVO> detail(@NotNull(message = "评价ID不能为空") Long commentId) throws BusinessException{
        log.info("会话评价内容详情：commentId={}", commentId);
        return PublicService.returnResponseVO(commentService.getDetail(commentId));
    }

    @ApiOperation(value = "回复评价")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentId", value = "评价id", required = true, dataType = "long", paramType = "query"),
            @ApiImplicitParam(name = "content", value = "回复内容", required = true, dataType = "string", paramType = "query")
    })
    @PostMapping("reply")
    public ResponseVO<Void> reply(@NotNull(message = "评价ID不能为空") Long commentId, @NotEmpty(message = "回复内容不能为空") String content) throws BusinessException{
        log.info("回复会话评价：commentId={}, content={}", commentId, content);
        commentService.replay(commentId, content);
        return PublicService.returnResponseVO(ExceptionCodes.SUCCESS);
    }


    /**
     * （医生端优化1.1）会话评价列表
     * @return
     * @throws BusinessException
     */
    @ApiOperation(value = "医生端-我的评价列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "doctorId", value = "医生id", required = true, dataType = "long", paramType = "query")
    })
    @PostMapping("/list")
    public PageVO<CommentDetailBO> commentList(@RequestParam Long doctorId, PageParamVO pageParamVO) throws BusinessException{
        log.info("会话评价列表：doctorId={}", doctorId);
        return commentService.findByDoctorId(doctorId, pageParamVO);
    }
}
